<!--系统管理-权限列表-->
<template>
  <div class="video-list-manage-parent" ref="parentContainer">
    <!--操作表单区域-->
    <div class="option-parent" ref="optionParentContainer">
      <el-form label-width="140px" style="padding-top: 10px">
        <el-row :gutter="0" :inline="true">
          <el-col :span="8">
            <el-form-item label="操作员姓名">
              <el-input v-model="supername" :disabled="isDisabled"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="操作员手机号">
              <el-input v-model="supermobile" :disabled="isDisabled"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
          </el-col>
          <el-col :span="4">
          </el-col>
          <el-col :span="4">
          </el-col>
        </el-row>
      </el-form>
    </div>

    <!--数据表格区域-->
    <div v-bind:style="{height:tableHeight+'px',width:'100%'}" v-loading="loading">
      <el-table :data="orderData.agent_operator_rights_all" border width="100%" height="100%"
                @selection-change="handleSelectionChange" ref="multipleTable">
        <el-table-column
          fixed
          type="selection"
          width="55">
        </el-table-column>
        <el-table-column
          label="权限ID"
          prop="actionid"
          width="100">
        </el-table-column>
        <el-table-column
          prop="actiontype"
          label="权限类别"
          width="120">
        </el-table-column>
        <el-table-column
          prop="name1"
          label="权限分类"
          width="120">
        </el-table-column>
        <el-table-column
          prop="name2"
          label="权限功能"
          min-width="120">
        </el-table-column>
        <el-table-column
          prop="actions"
          label="权限地址"
          min-width="120">
        </el-table-column>
      </el-table>
    </div>

    <!--翻页区域-->
    <div class="pagination-parent" style="text-align: left" ref="paginationParentContainer">
      <el-button type="success" style="margin-top: 10px;margin-left: 60px" @click="confirePreservation()">确认保存
      </el-button>
    </div>

  </div>
</template>

<script>
  import CPageBase from "../fragment/CPageBase"
  import CRootBase from "../fragment/CRootBase"

  export default {
    data() {
      return {
        pathArr: [
          {path: "/", name: "首页"},
          {path: "/container/sys_operator_list", name: "操作员列表"},
          {path: "/container/sys_operator_auth", name: "权限设置"},
        ],
        loading: false,
        orderData: "",//全部权限
        operatorRights: "",//已有去权限
        supername: "",
        supermobile: "",
        multipleSelection: [],
        isDisabled: true
      }
    },
    watch: {},
    mixins: [CPageBase, CRootBase],
    components: {},
    mounted() {

    },
    activated() {
      this.supername = this.$route.query.supername;
      this.supermobile = this.$route.query.supermobile;
      this.initCurrentPath();
      this.requestOrderData();
    },
    methods: {
      //初始化面包屑路径
      initCurrentPath() {
        this.$store.commit('changeCurrentLocation', this.pathArr);
      },

      //初始化选择状态
      initMultipleSelection() {
        let that = this;
        setTimeout(function () {
          for (let i = 0; i < that.operatorRights.agent_operator_rights_list.length; i++) {
            let orItem = that.operatorRights.agent_operator_rights_list[i];
            for (let j = 0; j < that.orderData.agent_operator_rights_all.length; j++) {
              let allItem = that.orderData.agent_operator_rights_all[j];
              if (orItem.actionid === allItem.actionid) {
                that.$refs.multipleTable.toggleRowSelection(allItem, true);
              }
            }
          }
        }, 0.5 * 1000);
      },

      //监听选择和反选状态
      handleSelectionChange(val) {
        this.multipleSelection = val;
      },

      //处理页面改变事件
      handleCurrentChange(currentPage) {
        this.start = this.start + this.limit;
        this.requestOrderData();
      },

      //点击查询按钮
      queryArticleByBtn() {
        this.start = 1;
        this.limit = 20;
        this.requestOrderData();
      },

      //获取全部权限列表
      requestOrderData() {
        let parameter = new URLSearchParams();
        parameter.append("action", "agent_operator_rights_all");
        let that = this;
        that.loading = true;
        this.$http.requestAuthData(that, parameter, function (data) {
          that.orderData = data;
          that.requestOperatorRights();
        });
      },

      //获取已有的权限列表
      requestOperatorRights() {
        let parameter = new URLSearchParams();
        parameter.append("action", "agent_operator_rights_list");
        parameter.append("opermobile", this.supermobile);
        let that = this;
        that.loading = true;
        this.$http.requestAuthData(that, parameter, function (data) {
          that.operatorRights = data;
          that.initMultipleSelection()
        });
      },

      //提交设置的权限
      confirePreservation() {
        if (this.multipleSelection.length === 0) {
          this.$message({message: '未勾选任何权限！', type: 'warning'});
          return;
        }
        let parameter = new URLSearchParams();
        let actionid_list = [];
        for (let i = 0; i < this.multipleSelection.length; i++) {
          let actionid = this.multipleSelection[i].actionid;
          actionid_list.push(actionid);
          parameter.append("actionid_list", actionid);
        }

        parameter.append("action", "agent_operator_rights_modify");
        parameter.append("opermobile", this.supermobile);

        let that = this;
        that.loading = true;
        this.$http.requestAuthData(that, parameter, function (data) {
          that.$message({message: '保存成功！',type:"success"});
          that.$router.go(-1);
        });
      }
    }
  }
</script>

<style lang="scss" scoped="" type="text/scss" src="../../assets/style/list-type-pages.scss">

</style>

